home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Magic Image Java Applet Commercial v1.0 / magici2.exe / magicimage.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-02-26  |  6.3 KB  |  325 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.awt.Frame;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.MediaTracker;
  9. import java.net.URL;
  10.  
  11. public class magicimage extends Applet implements Runnable {
  12.    Thread runner;
  13.    String image_align = "left";
  14.    String image_valign = "left";
  15.    String bgcolor = "";
  16.    String target_frame = "";
  17.    String infostr = "";
  18.    String link1 = "";
  19.    String scroll_way = "";
  20.    String status_bar = "";
  21.    String regcode = "";
  22.    String errstr = "";
  23.    Image offimg;
  24.    Image offimg2;
  25.    Image imgust;
  26.    Image imgalt;
  27.    int bgci;
  28.    int genislik;
  29.    int yukseklik;
  30.    int delay_time;
  31.    int durum;
  32.    // $FF: renamed from: X int
  33.    int field_0;
  34.    int imgwidth;
  35.    int imgheight;
  36.    int kaplaboy;
  37.    int kaplayuk;
  38.    int don;
  39.    int don2;
  40.    // $FF: renamed from: XX int
  41.    int field_1;
  42.    // $FF: renamed from: YY int
  43.    int field_2;
  44.    int imgw;
  45.    int imgh;
  46.    Color bgc;
  47.    MediaTracker tracker;
  48.    Graphics offScreeng;
  49.    Graphics offScreeng2;
  50.    // $FF: renamed from: u java.net.URL
  51.    URL field_3;
  52.    boolean inf = false;
  53.    // $FF: renamed from: rg boolean
  54.    boolean field_4 = false;
  55.    boolean whb = false;
  56.  
  57.    public void init() {
  58.       this.genislik = -1;
  59.       this.yukseklik = -1;
  60.       this.whb = false;
  61.       this.durum = 0;
  62.       this.field_0 = 0;
  63.       this.kaplaboy = 0;
  64.       this.kaplayuk = 0;
  65.       this.bgcolor = ((Applet)this).getParameter("bgcolor");
  66.  
  67.       try {
  68.          this.bgci = Integer.parseInt(this.bgcolor, 16);
  69.       } catch (Exception var2) {
  70.          this.bgci = 0;
  71.       }
  72.  
  73.       this.bgc = new Color(this.bgci);
  74.       ((Component)this).setBackground(this.bgc);
  75.       this.image_align = ((Applet)this).getParameter("image_align");
  76.       this.image_valign = ((Applet)this).getParameter("image_valign");
  77.       this.link1 = ((Applet)this).getParameter("link");
  78.       this.regcode = ((Applet)this).getParameter("regcode");
  79.       if (this.regcode != null && this.regcode.equals("mimg35856")) {
  80.          this.field_4 = true;
  81.       }
  82.  
  83.       this.infostr = ((Applet)this).getParameter("info");
  84.       this.status_bar = ((Applet)this).getParameter("status_bar");
  85.       this.scroll_way = ((Applet)this).getParameter("scroll_way");
  86.       this.target_frame = ((Applet)this).getParameter("target_frame");
  87.  
  88.       try {
  89.          this.delay_time = Integer.parseInt("" + ((Applet)this).getParameter("delay_time"), 10);
  90.       } catch (Exception var1) {
  91.          this.delay_time = 2000;
  92.       }
  93.  
  94.       this.tracker = new MediaTracker(this);
  95.       this.imgust = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("foreground_image"));
  96.       this.imgalt = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("background_image"));
  97.       this.tracker.addImage(this.imgust, 1);
  98.       this.tracker.addImage(this.imgalt, 2);
  99.    }
  100.  
  101.    public void update(Graphics var1) {
  102.       if (this.whb) {
  103.          this.offScreeng.setColor(this.bgc);
  104.          this.offScreeng.fillRect(0, 0, this.genislik, this.yukseklik);
  105.          if (this.durum == 0) {
  106.             this.offScreeng.setColor(Color.black);
  107.             this.offScreeng.drawString("Loading...", 10, 20);
  108.             this.offScreeng.setColor(this.bgc);
  109.          }
  110.  
  111.          if (this.durum == 1) {
  112.             this.offScreeng.setColor(Color.black);
  113.             this.offScreeng.drawString("" + this.errstr, 10, 20);
  114.             this.offScreeng.setColor(this.bgc);
  115.          }
  116.  
  117.          if (this.durum == 2) {
  118.             this.offScreeng.drawImage(this.offimg2, this.field_0, 0, this);
  119.             this.offScreeng.drawImage(this.imgust, this.field_1, this.field_2, this);
  120.          }
  121.  
  122.          this.paint(var1);
  123.       }
  124.  
  125.    }
  126.  
  127.    public void paint(Graphics var1) {
  128.       if (this.whb) {
  129.          var1.drawImage(this.offimg, 0, 0, this);
  130.       }
  131.  
  132.    }
  133.  
  134.    public boolean mouseDown(Event var1, int var2, int var3) {
  135.       try {
  136.          this.field_3 = new URL("" + this.link1);
  137.          ((Applet)this).getAppletContext().showDocument(this.field_3, this.target_frame);
  138.          return true;
  139.       } catch (Exception var4) {
  140.          return true;
  141.       }
  142.    }
  143.  
  144.    public void start() {
  145.       if (this.runner == null || !this.runner.isAlive()) {
  146.          this.runner = new Thread(this);
  147.       }
  148.  
  149.       this.runner.start();
  150.    }
  151.  
  152.    public void stop() {
  153.       if (this.runner != null) {
  154.          this.runner.stop();
  155.          this.runner = null;
  156.       }
  157.  
  158.    }
  159.  
  160.    public void destroy() {
  161.       this.runner = null;
  162.    }
  163.  
  164.    public boolean mouseEnter(Event var1, int var2, int var3) {
  165.       if (this.whb) {
  166.          if (this.field_4) {
  167.             if (this.status_bar != null) {
  168.                ((Applet)this).showStatus("" + this.status_bar);
  169.             }
  170.          } else {
  171.             ((Applet)this).showStatus("  Unregistered version of MagicImage Java applet. URL: japplets.tripod.com");
  172.          }
  173.  
  174.          this.runner.suspend();
  175.          if (this.link1 == null) {
  176.             return true;
  177.          }
  178.  
  179.          if (this.link1.equals("") || this.link1.equals(" ")) {
  180.             return true;
  181.          }
  182.  
  183.          ((Frame)((Component)this).getParent()).setCursor(12);
  184.       }
  185.  
  186.       return true;
  187.    }
  188.  
  189.    public boolean mouseExit(Event var1, int var2, int var3) {
  190.       if (this.whb) {
  191.          ((Applet)this).showStatus("");
  192.          this.runner.resume();
  193.          ((Frame)((Component)this).getParent()).setCursor(0);
  194.       }
  195.  
  196.       return true;
  197.    }
  198.  
  199.    public void run() {
  200.       ((Component)this).show();
  201.       this.genislik = ((Component)this).size().width;
  202.       this.yukseklik = ((Component)this).size().height;
  203.       if (!this.whb) {
  204.          this.offimg = ((Component)this).createImage(this.genislik, this.yukseklik);
  205.          this.offScreeng = this.offimg.getGraphics();
  206.       }
  207.  
  208.       this.whb = true;
  209.       ((Component)this).repaint();
  210.  
  211.       try {
  212.          this.tracker.waitForAll();
  213.       } catch (InterruptedException var4) {
  214.       }
  215.  
  216.       if (this.tracker.isErrorAny()) {
  217.          this.durum = 1;
  218.          this.errstr = "Image Error !";
  219.       } else {
  220.          this.imgw = this.imgust.getWidth(this);
  221.          this.imgh = this.imgust.getHeight(this);
  222.          this.imgwidth = this.imgalt.getWidth(this);
  223.          this.imgheight = this.imgalt.getHeight(this);
  224.          this.field_1 = 0;
  225.          this.field_2 = 0;
  226.          if (this.image_align != null && this.imgw < this.genislik) {
  227.             if (this.image_align.equals("center")) {
  228.                this.field_1 = (this.genislik - this.imgw) / 2;
  229.             }
  230.  
  231.             if (this.image_align.equals("right")) {
  232.                this.field_1 = this.genislik - this.imgw;
  233.             }
  234.          }
  235.  
  236.          if (this.image_valign != null && this.imgh < this.yukseklik) {
  237.             if (this.image_valign.equals("center")) {
  238.                this.field_2 = (this.yukseklik - this.imgh) / 2;
  239.             }
  240.  
  241.             if (this.image_valign.equals("bottom")) {
  242.                this.field_2 = this.yukseklik - this.imgh;
  243.             }
  244.          }
  245.  
  246.          int var1 = 0;
  247.          int var2 = 0;
  248.          this.kaplaboy = 0;
  249.          this.kaplayuk = 0;
  250.          if (this.imgwidth >= this.genislik) {
  251.             this.kaplaboy = this.imgwidth + this.imgwidth;
  252.             var1 = 1;
  253.          } else {
  254.             while(this.kaplaboy < this.genislik) {
  255.                this.kaplaboy += this.imgwidth;
  256.                ++var1;
  257.             }
  258.  
  259.             this.kaplaboy += this.imgwidth;
  260.          }
  261.  
  262.          if (this.imgheight >= this.yukseklik) {
  263.             this.kaplayuk = this.imgheight;
  264.             var2 = 0;
  265.          } else {
  266.             while(this.kaplayuk < this.yukseklik) {
  267.                this.kaplayuk += this.imgheight;
  268.                ++var2;
  269.             }
  270.  
  271.             --var2;
  272.          }
  273.  
  274.          this.offimg2 = ((Component)this).createImage(this.kaplaboy, this.yukseklik);
  275.          this.offScreeng2 = this.offimg2.getGraphics();
  276.          this.offScreeng2.setColor(this.bgc);
  277.          this.offScreeng2.fillRect(0, 0, this.kaplaboy, this.yukseklik);
  278.  
  279.          for(this.don2 = 0; this.don2 <= var2; ++this.don2) {
  280.             for(this.don = 0; this.don <= var1; ++this.don) {
  281.                this.offScreeng2.drawImage(this.imgalt, this.don * this.imgwidth, this.don2 * this.imgheight, this);
  282.             }
  283.          }
  284.  
  285.          this.offScreeng2.dispose();
  286.          this.field_0 = -this.imgwidth;
  287.          this.durum = 2;
  288.       }
  289.  
  290.       this.field_0 = -this.imgwidth;
  291.       if (this.infostr != null) {
  292.          if (!this.infostr.equals("Applet by Gokhan Dagli,japplets.tripod.com")) {
  293.             this.durum = 1;
  294.             this.errstr = "info parameter error!";
  295.          }
  296.       } else {
  297.          this.durum = 1;
  298.          this.errstr = "info parameter error!";
  299.       }
  300.  
  301.       ((Component)this).repaint();
  302.  
  303.       while(true) {
  304.          try {
  305.             Thread.sleep((long)this.delay_time);
  306.          } catch (InterruptedException var3) {
  307.          }
  308.  
  309.          if (this.scroll_way.equals("false")) {
  310.             --this.field_0;
  311.             if (this.field_0 <= -this.imgwidth) {
  312.                this.field_0 = 0;
  313.             }
  314.          } else {
  315.             ++this.field_0;
  316.             if (this.field_0 >= 0) {
  317.                this.field_0 = -this.imgwidth;
  318.             }
  319.          }
  320.  
  321.          ((Component)this).repaint();
  322.       }
  323.    }
  324. }
  325.